import logging
from tinyops.config import Config
from tinyops.notifier import NotifierManager


LOG = logging.getLogger(__name__)


class AlerterManager:
    def __init__(self, config: Config) -> None:
        notifier = None
        if config.alerter:
            notifier_manager = NotifierManager(config)
            notifier = notifier_manager.create(*config.alerter.notifier)
        self.notifier = notifier

    def send(self, title: str, body: str) -> None:
        if not self.notifier:
            LOG.info('alerter not configured')
            return
        self.notifier.notify(title=title, content=body)
